package core.schedule.snake.schedule.job;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import core.schedule.snake.data.domain.DsfaTask;
import core.schedule.snake.data.domain.TaskResult;
import core.schedule.snake.schedule.core.ScanService;
import core.schedule.snake.schedule.core.TaskInfo;
import core.schedule.snake.schedule.impl.TaskTypeInterface;
import core.tool.log.log4j.EasyLogger;

public class DSFATaskJob implements Job {

	private DsfaTask dsfaTask;
	
	private TaskInfo taskInfo ;
	
	
	public DSFATaskJob(DsfaTask dsfaTask, TaskInfo taskInfo) {
		super();
		this.dsfaTask = dsfaTask;
		this.taskInfo = taskInfo;
	}


	public DSFATaskJob() {
		
	}
	

	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		DSFATaskJob job=(DSFATaskJob) arg0.getJobDetail().getJobDataMap().get("JOB");
		this.dsfaTask=job.getDsfaTask();
		this.taskInfo=job.getTaskInfo();
		boolean flag = false;
		EasyLogger.info("执行任务名称：" + dsfaTask.getTaskName());
		TaskTypeInterface taskTypeInterface = ScanService.getTaskTypeInterface(dsfaTask, taskInfo);
		if (taskTypeInterface != null) {
			EasyLogger.debug("任务实现接口：" + taskTypeInterface.getClass());
			Object object = taskTypeInterface.getTaskConfigInfo(dsfaTask);
			EasyLogger.debug("序列化任务执行参数（Xml---JavaBean）完成");
			TaskResult taskResult = taskTypeInterface.operateTask(dsfaTask, object);
			EasyLogger.info("任务执行结果："+ taskResult.getExecuteDesc());
			if (!taskResult.isExecuteFlag()) {
				flag = true;
			}
		}
	}


	public DsfaTask getDsfaTask() {
		return dsfaTask;
	}


	public void setDsfaTask(DsfaTask dsfaTask) {
		this.dsfaTask = dsfaTask;
	}


	public TaskInfo getTaskInfo() {
		return taskInfo;
	}


	public void setTaskInfo(TaskInfo taskInfo) {
		this.taskInfo = taskInfo;
	}
	
	

}
